<template>
  <div>
    <!-- 添加按钮 -->
    <el-button type="primary" @click="willAdd">添加</el-button>
    <!-- 列表表格 -->
    <v-list @edit="willEdit" :list="list" @init="init"></v-list>
    <!-- 弹框 -->
    <v-form ref="form" :info="info" :list="list" @init="init"></v-form>
  </div>
</template>
<script>
import vList from "./components/list.vue";
import vForm from "./components/form.vue";
import { reqmenulist } from "../../request/api";
export default {
  components: {
    vList,
    vForm,
  },
  data() {
    return {
      list: [],
      info: {
        isshow: false,
        isAdd: true, //用来判断是添加还是编辑
      },
    };
  },
  mounted() {
    //请数据
    this.init();
  },
  methods: {
    //点了添加
    willAdd() {
      this.info = {
        isshow: true,
        isAdd: true,
      };
    },
    //点了编辑
    willEdit(id) {
      this.info = {
        isshow: true,
        isAdd: false,
      };
      //通知form调用getOne
      this.$refs.form.getOne(id)

    },
    //进来就获取数据
    init() {
      //请数据
      reqmenulist({istree:true}).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.list;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
@import "../../less/index.less";
div {
  padding: @margin;
}
</style>